<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>预约记录</title>
    <link rel="stylesheet" href="../css/page-health-order.css"/>

    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">

</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div class="app" id="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">预约记录</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>

    <!--时间查询框-->
    <div id="center">
        <div>
            <div style="text-align: center;font-size: 20px;color: blue">可选择日期范围进行查询</div>
            <div style="line-height: 60px">
                <template>
                    <div class="block">
                        <span class="demonstration">开始日期</span>
                        <el-date-picker
                                v-model="value1"
                                type="date"
                                placeholder="选择日期"
                                format="yyyy 年 MM 月 dd 日"
                                value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </div>
                    <div class="block">
                        <span class="demonstration">结束日期</span>
                        <el-date-picker
                                v-model="value2"
                                type="date"
                                placeholder="选择日期"
                                format="yyyy 年 MM 月 dd 日"
                                value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </div>
                </template>
            </div>
            <div style="line-height: 50px">
                <button type="button" @click="selectByDate()" style="font-size: 18px">查询</button>
            </div>
        </div>

    </div>


    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="list-column1">
            <ul class="list">
                <li class="list-item" v-for="item in orderSetmealList">
                    <a class="link-page" :href="'order_detail.html?id='+item.orderId">
                        <img class="img-object f-left" :src="'http://qiuo4nrcv.hn-bkt.clouddn.com/'+item.img" alt="">
                        <div class="item-body">
                            <h4 class="ellipsis item-title" style="color: blue">体检人:{{item.orderPerson}}</h4>
                            <p class="ellipsis-more item-desc">预约套餐:{{item.name}}</p>
                            <p class="item-keywords">
                                <span>点击查询预约详情</span>
                            </p>
                        </div>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript">
    var vue = new Vue({
        el: '#app',
        data: {
            //模型数据用于展示套餐列表
            orderSetmealList: [],
            //会员信息
            memberInfo: {},
            value1: '',
            value2: '',
        },
        methods: {
            selectByDate() {
                if (this.value2!='' &&this.value1>this.value2){
                    let tem=this.value1;
                    this.value1=this.value2;
                    this.value2=tem;
                    //this.$message.error("日期选择有误已自动优化!");
                }
                axios.post("/setmeal/getOrderSetmealByMemberId.do", {
                    memberId: this.memberInfo.id, beginDate: this.value1, endDate: this.value2
                }).then((res) => {
                    if (res.data.flag) {
                        //查询成功
                        this.orderSetmealList = res.data.data;
                        if (this.orderSetmealList.length==0){
                            this.$message.success("当前时间未查询到预约记录!");
                        }else{
                            this.$message({
                                center:true,
                                message:res.data.message,
                                type:'success'
                            });
                        }
                    } else {
                        //查询失败,弹出提示信息
                        this.$message({
                            type: 'error',
                            message: res.data.message,
                            center: true
                        });
                    }
                });

            }
        },
        mounted() {
            //检查登录状态检查完毕后发送ajax请求将页面相关数据进行回填
            axios.post("/member/checkLogin.do").then((res) => {
                if (res.data.flag) {
                    //查询成功，为模型数据赋值
                    this.memberInfo = res.data.data;
                    //alert(this.memberInfo.id);
                    //let regTime=this.memberInfo.regTime;
                    /*this.memberInfo.regTime=this.memberInfo.regTime.split(" ")[0];
                    if (this.memberInfo.birthday!=null){
                        this.memberInfo.birthday=this.memberInfo.birthday.split(" ")[0];
                    }*/
                    axios.post("/setmeal/getOrderSetmealByMemberId.do", {
                        memberId: this.memberInfo.id, beginDate: this.value1, endDate: this.value2
                    }).then((res) => {
                        if (res.data.flag) {
                            //查询成功
                            this.orderSetmealList = res.data.data;
                            //console.log(this.orderSetmealList);
                            if (this.orderSetmealList.length==0){
                                this.$message.success("当前暂无预约记录!");
                            }
                        } else {
                            //查询失败,弹出提示信息
                            this.$message({
                                type: 'error',
                                message: res.data.message,
                                center: true
                            });
                        }
                    });
                } else {
                    location.href = "/pages/login.html";
                    return false;
                }
            })
            .catch(() => {
                            this.$message("请求出错请重新登录!");
                            location.href = "/pages/login.html";
                            return false;
                        });


                        //发送ajax请求，获取所有的套餐数据，赋值给setmealList模型数据，用于数据展示
            /*axios.post("/setmeal/getSetmealByMemberId.do",{params:{id:this.memberInfo.id}}).then((res) => {
                if (res.data.flag) {
                    //查询成功
                    this.setmealList = res.data.data;
                } else {
                    //查询失败,弹出提示信息
                    this.$message({
                        type: 'error',
                        message: res.data.message,
                        center: true
                    });
                }
            });*/
        }
    });
</script>
</body>